import axios from 'axios';
import {
  EmployeeView,
  EmployeeSignUpLinkCmd,
  EmployeeSignUpLinkView,
  EmployeeUptCmd,
  EmployeeStatusUptCmd,
  EmployeeQry,
  EmployeePageQry,
} from '@/types/idm/employee';
import { EnumCountView, Page } from '@/types/global-business';
import qs from 'query-string';

export function createEmployeeSignUpLink(data: EmployeeSignUpLinkCmd) {
  return axios.post<EmployeeSignUpLinkView>(
    '/idm/user/employee/sign-up-link',
    data
  );
}

export function updateEmployee(data: EmployeeUptCmd) {
  return axios.put<EmployeeView>('/idm/user/employee', data);
}

export function updateEmployeeStatus(data: EmployeeStatusUptCmd) {
  return axios.put('/idm/user/employee/status', data);
}

export function fetchEmployee(params: EmployeeQry) {
  return axios.get<EmployeeView>('/idm/user/employee/one', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export function countEmployeeStatus(params: EmployeePageQry) {
  return axios.get<EnumCountView[]>('/idm/user/employee/status-count', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export function fetchEmployeePage(params: EmployeePageQry) {
  return axios.get<Page<EmployeeView>>('/idm/user/employee/page', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}
